/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package BL;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

/**
 *
 * @author sundas
 */
@Entity
@Table(name = "stockproduct", catalog = "newPurchase", schema = "", uniqueConstraints = {@UniqueConstraint(columnNames = {"stockId", "productNumber"})})
@NamedQueries({@NamedQuery(name = "Stockproduct.findAll", query = "SELECT s FROM Stockproduct s"), @NamedQuery(name = "Stockproduct.findByStockId", query = "SELECT s FROM Stockproduct s WHERE s.stockproductPK.stockId = :stockId"), @NamedQuery(name = "Stockproduct.findByRcvdQty", query = "SELECT s FROM Stockproduct s WHERE s.rcvdQty = :rcvdQty"), @NamedQuery(name = "Stockproduct.findByProductNumber", query = "SELECT s FROM Stockproduct s WHERE s.stockproductPK.productNumber = :productNumber"), @NamedQuery(name = "Stockproduct.findByExpiryDate", query = "SELECT s FROM Stockproduct s WHERE s.expiryDate = :expiryDate"), @NamedQuery(name = "Stockproduct.findByPurchasePrice", query = "SELECT s FROM Stockproduct s WHERE s.purchasePrice = :purchasePrice"), @NamedQuery(name = "Stockproduct.findByConsumedQty", query = "SELECT s FROM Stockproduct s WHERE s.consumedQty = :consumedQty"), @NamedQuery(name = "Stockproduct.findByDiscount", query = "SELECT s FROM Stockproduct s WHERE s.discount = :discount"), @NamedQuery(name = "Stockproduct.findByUnit", query = "SELECT s FROM Stockproduct s WHERE s.unit = :unit")})
public class Stockproduct implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected StockproductPK stockproductPK;
    @Column(name = "rcvdQty")
    private Integer rcvdQty;
    @Column(name = "expiryDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date expiryDate;
    @Column(name = "purchasePrice", precision = 12)
    private Float purchasePrice;
    @Column(name = "consumedQty")
    private Integer consumedQty;
    @Column(name = "discount", precision = 12)
    private Float discount;
    @Column(name = "unit", length = 10)
    private String unit;
    @JoinColumn(name = "stockId", referencedColumnName = "stockId", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Stock stock;
    @JoinColumn(name = "productNumber", referencedColumnName = "productNumber", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Product product;

    public Stockproduct() {
    }

    public Stockproduct(StockproductPK stockproductPK) {
        this.stockproductPK = stockproductPK;
    }

    public Stockproduct(int stockId, int productNumber) {
        this.stockproductPK = new StockproductPK(stockId, productNumber);
    }

    public StockproductPK getStockproductPK() {
        return stockproductPK;
    }

    public void setStockproductPK(StockproductPK stockproductPK) {
        this.stockproductPK = stockproductPK;
    }

    public Integer getRcvdQty() {
        return rcvdQty;
    }

    public void setRcvdQty(Integer rcvdQty) {
        this.rcvdQty = rcvdQty;
    }

    public Date getExpiryDate() {
        return expiryDate;
    }

    public void setExpiryDate(Date expiryDate) {
        this.expiryDate = expiryDate;
    }

    public Float getPurchasePrice() {
        return purchasePrice;
    }

    public void setPurchasePrice(Float purchasePrice) {
        this.purchasePrice = purchasePrice;
    }

    public Integer getConsumedQty() {
        return consumedQty;
    }

    public void setConsumedQty(Integer consumedQty) {
        this.consumedQty = consumedQty;
    }

    public Float getDiscount() {
        return discount;
    }

    public void setDiscount(Float discount) {
        this.discount = discount;
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    public Stock getStock() {
        return stock;
    }

    public void setStock(Stock stock) {
        this.stock = stock;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (stockproductPK != null ? stockproductPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Stockproduct)) {
            return false;
        }
        Stockproduct other = (Stockproduct) object;
        if ((this.stockproductPK == null && other.stockproductPK != null) || (this.stockproductPK != null && !this.stockproductPK.equals(other.stockproductPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "DB.Stockproduct[stockproductPK=" + stockproductPK + "]";
    }

}
